<template>
  <div class="table-wrap">
    <div class="table-header">
      <div class="header-item" v-for="(item, index) in $t('OpportunityPrediction.tableHeaderArr')" :key="index">
        {{item}}
      </div>
    </div>
    <div class="table-content" v-for="(item, index) in tableContentData" :key="index" v-if="tableContentData.length !== 0">
      <div class="left" :style="{height: item.detail.length * 30 +'px', 'line-height': item.detail.length * 30 +'px'}">
        <div class="left-item">
          {{item.date}}
        </div>
        <div class="left-item">
          {{item.number}}
        </div>
      </div>
      <div class="right">
        <div v-for="(item2, index2) in item.detail" :key="index2" style="display: block;">
          <div class="right-item" @click="toggleDetail(item2)">
            <i :class="{'el-icon-arrow-right': !item2.showFlag,'el-icon-arrow-down': item2.showFlag} "
               style="position: absolute; top: 10px; left: 5px;"></i>
            <div class="content-item">
              {{item2.detail_num}}
            </div>
            <el-tooltip class="item" effect="dark" :content="item2.detail_name" placement="top">
              <div class="content-item"
                   style="width: 20%;overflow: hidden; text-overflow:ellipsis; white-space: nowrap; vertical-align: middle;">
                {{item2.detail_name}}
              </div>
            </el-tooltip>
            <div class="content-item">
              $ {{item2.detail_money}}
            </div>
            <div class="content-item" style="width: 12%;">
              {{item2.detail_state}}
            </div>
            <div class="content-item">
              {{item2.detail_prediction}}%
            </div>
            <div class="content-item">
              {{item2.detail_time}}
            </div>
          </div>
          <div class="item-detail" v-show="item2.showFlag">
            <div class="list">
              <el-row class="top-row">
                <el-col :span="5">
                  <div class="list-item">
                    <span>
                      {{$t('OpportunityPrediction.BusinessOpportunityType')}}:
                    </span>
                    <span class="list-item-value">{{item2.detail_data.type}}</span>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="list-item">
                    <span>
                      {{$t('OpportunityPrediction.SourcesOfBusinessOpportunities')}}:
                    </span>
                    <span class="list-item-value">{{item2.detail_data.origin}}</span>
                  </div>
                </el-col>
                <el-col :span="7">
                  <div class="list-item">
                    <span>
                      {{$t('OpportunityPrediction.SalesForecastDaysToWin')}}:
                    </span>
                    <span class="list-item-value">{{item2.detail_data.time}}</span>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="list-item">
                    <span>
                      {{$t('OpportunityPrediction.ProjectScaleVolume')}}:
                    </span>
                    <span class="list-item-value">{{item2.detail_data.scale}}</span>
                  </div>
                </el-col>
              </el-row>
              <el-row class="bottom-row">
                <el-col :span="5">
                  <div class="list-item">
                    <span>
                     {{$t('OpportunityPrediction.ManagementPartition')}}:
                    </span>
                    <span class="list-item-value">{{item2.detail_data.area}}</span>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="list-item">
                    <span>
                     {{$t('OpportunityPrediction.CustomerService')}}:
                    </span>
                    <span class="list-item-value">{{item2.detail_data.place}}</span>
                  </div>
                </el-col>
                <el-col :span="7">
                  <div class="list-item">
                    <span>
                     {{$t('OpportunityPrediction.GPMaori')}}:
                    </span>
                    <span class="list-item-value">{{item2.detail_data.profit}}</span>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="list-item">
                    <span>
                      {{$t('OpportunityPrediction.ProcurementType')}}:
                    </span>
                    <span class="list-item-value">{{item2.detail_data.mode}}</span>
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div v-else>
      <p>No Data...</p>
    </div>
  </div>
</template>
<style lang="scss" scoped>

  .table-wrap {
    box-sizing: border-box;
    border: 1px solid #999;
    background-color: #fff;
    user-select: none;
     -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    &:after {
      content: "";
      display: block;
      visibility: hidden;
      clear: both;
      height: 0;
    }
    .table-header {
      position: relative;
      width: 100%;
      height: 50px;
      line-height: 50px;
      background-color: #bceaff;
      div {
        display: inline-block;
      }
      .header-item {
        text-align: center;
        width: 12.5%;
        box-sizing: border-box;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
        vertical-align: middle;
        &:nth-child(1) {
          width: 12%;
        }
        &:nth-child(2) {
          /*width: 13%;*/
          width: 11%;
        }
        &:nth-child(3) {
          width: 11%;
        }
        &:nth-child(4) {
          /*width: 14.5%;*/
          width: 17%;
        }
        &:nth-child(5) {
          /*padding-left: 54px;*/
        }
        &:nth-child(6) {
          width:11%;
        }
        &:nth-child(7) {
          padding-right: 20px;
          width:14%;
        }
        &:nth-child(8) {
          /*padding-right: 44px;*/
          width: 12%;
          margin-left: -20px;
        }
      }
    }
    .table-content {
      position: relative;
      width: 100%;
      border: 1px solid #999;
      &:after {
        content: "";
        display: block;
        visibility: hidden;
        clear: both;
        height: 0;
      }
      .left {
        /*width: 25%;*/
        width: 23%;
        float: left;
        position: relative;
        box-sizing: border-box;
        /*border-right: 1px solid #999;*/
        div {
          display: inline-block;
          width: 49%;
          text-align: center;
          height: 30px;
          line-height: 30px;
        }
      }
      .right {
        /*width: 75%;*/
        width: 77%;
        float: left;
        position: relative;
        border-left: 1px solid #999;
        box-sizing: border-box;
        div {
          display: inline-block;
        }
        .right-item {
          width: 100%;
          border-bottom: 1px solid #ccc;
          position: relative;
          cursor: pointer;
          .content-item {
            width: 16%;
            text-align: center;
            height: 30px;
            line-height: 30px;
          }
        }
        .item-detail {
          display: block;
          background-color: #f5f5f5;
          div {
            display: block;
          }
          .list {
            padding: 0 20px;
            /*height: 60px;*/
            border: 1px solid #ccc;
          }
          .top-row {
            margin-top: 10px;
            margin-bottom: 10px;
          }
          .bottom-row {
            margin-bottom: 10px;
          }
          .list-item{
            span{
              overflow: hidden;
              text-overflow:ellipsis;
              white-space: nowrap;
              vertical-align: middle;
              display: inline-block;
              /*max-width: 95px;*/
              /*max-width: 45%;*/
            }
            .list-item-value {
              color: #666;
            }
          }
        }
      }
    }
  }
</style>
<script>
  export default {
    data() {
      return {
        leftHeight: '',
        tableHeaderArr: ['提交日期', '立项编号', '行项目编号', '客户名称', '行项目金额', '当前状态', '预测成单率', '预测时间'],
        tableContentData: [],
        // tableContentData: [
        //   {
        //     date: '20181017',
        //     number: '123456789',
        //     detail: [
        //       {
        //         detail_num: '12345',
        //         detail_name: '中铁十三局',
        //         detail_money: '8700',
        //         detail_state: '未落单',
        //         detail_prediction: '75',
        //         detail_time: '20181023',
        //         showFlag: false,
        //         detail_data: {
        //           type: '重要',
        //           origin: 'IS',
        //           time: '3个月',
        //           scale: '大规模',
        //           area: '华北',
        //           place: '北京',
        //           profit: '1.00',
        //           mode: '采集'
        //         }
        //       },
        //       {
        //         detail_num: '34532',
        //         detail_name: '中铁局',
        //         detail_money: '8700',
        //         detail_state: '未落单',
        //         detail_prediction: '75',
        //         detail_time: '20181023',
        //         showFlag: false,
        //         detail_data: {
        //           type: '重要',
        //           origin: 'IS',
        //           time: '3个月',
        //           scale: '大规模',
        //           area: '华北',
        //           place: '北京',
        //           profit: '1.00',
        //           mode: '采集'
        //         }
        //       },
        //       {
        //         detail_num: '3443546',
        //         detail_name: '中铁十三局',
        //         detail_money: '8700',
        //         detail_state: '未落单',
        //         detail_prediction: '75',
        //         detail_time: '20181023',
        //         showFlag: false,
        //         detail_data: {
        //           type: '重要',
        //           origin: 'IS',
        //           time: '3个月',
        //           scale: '大规模',
        //           area: '华北',
        //           place: '北京',
        //           profit: '1.00',
        //           mode: '采集'
        //         }
        //       }
        //     ]
        //   },
        //   {
        //     date: '20181017',
        //     number: '3453545',
        //     detail: [
        //       {
        //         detail_num: '12345',
        //         detail_name: '中铁十三局',
        //         detail_money: '8700',
        //         detail_state: '未落单',
        //         detail_prediction: '75',
        //         detail_time: '20181023',
        //         detail_data: {
        //           type: '重要',
        //           origin: 'IS',
        //           time: '3个月',
        //           scale: '大规模',
        //           area: '华北',
        //           place: '北京',
        //           profit: '1.00',
        //           mode: '采集'
        //         }
        //       },
        //       {
        //         detail_num: '34532',
        //         detail_name: '中铁局',
        //         detail_money: '8700',
        //         detail_state: '未落单',
        //         detail_prediction: '75',
        //         detail_time: '20181023',
        //         detail_data: {
        //           type: '重要',
        //           origin: 'IS',
        //           time: '3个月',
        //           scale: '大规模',
        //           area: '华北',
        //           place: '北京',
        //           profit: '1.00',
        //           mode: '采集'
        //         }
        //       },
        //       {
        //         detail_num: '3443546',
        //         detail_name: '中铁十三局',
        //         detail_money: '8700',
        //         detail_state: '未落单',
        //         detail_prediction: '75',
        //         detail_time: '20181023',
        //         detail_data: {
        //           type: '重要',
        //           origin: 'IS',
        //           time: '3个月',
        //           scale: '大规模',
        //           area: '华北',
        //           place: '北京',
        //           profit: '1.00',
        //           mode: '采集'
        //         }
        //       }
        //     ]
        //   },
        // ],
      }
    },
    methods: {
      toggleDetail(data) {
        console.log(data.showFlag, '原来的')
        data.showFlag = !data.showFlag
        console.log(data.showFlag, '改变的')
      }
    },
    props: ['tableWrapData'],
    watch: {
      tableWrapData: function (nVal) {
        this.tableContentData = nVal
      }
    }
  }
</script>
